/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package testinggggg;
import java.io.File;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.xml.XMLConstants;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;
import javax.xml.transform.sax.SAXSource;
import javax.xml.validation.Schema;
import javax.xml.validation.SchemaFactory;
import javax.xml.validation.Validator;
import org.w3c.dom.Document;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.DefaultHandler;


/**
 *
 * @author lengogiang
 */
public class XSDValidate {

    public static void main(String[] args) {
        try {
            ///SAX XSD

            String xml ="test.xml";
            String xsd= "test.xsd";

            SchemaFactory xFac = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
            Schema schema = xFac.newSchema(new File(xsd));
            
            SAXSource sSource = new SAXSource(new InputSource(xml));
            
            Validator validator = schema.newValidator();
            validator.validate(sSource);
            
        } catch (Exception e) {
            System.out.println(e.getMessage());
        }
    }
}